#include "RedisWrapper.h"
#include <iostream>
#include <vector>
#include <unordered_map>

int main() {
    try {
        // Create RedisWrapper instance
        RedisWrapper redis("tcp://127.0.0.1:6379");

        // String operations
        std::cout << "=== String Operations ===" << std::endl;
        if (redis.set("name", "redis++ wrapper")) {
            std::cout << "SET name successful" << std::endl;
        }

        auto name = redis.get("name");
        if (name) {
            std::cout << "GET name: " << *name << std::endl;
        }

        // List operations
        std::cout << "\n=== List Operations ===" << std::endl;
        redis.lpush("tasks", "task1");
        redis.rpush("tasks", "task2");
        redis.rpush("tasks", "task3");

        auto task = redis.lpop("tasks");
        if (task) {
            std::cout << "LPOP task: " << *task << std::endl;
        }

        // Hash operations
        std::cout << "\n=== Hash Operations ===" << std::endl;
        redis.hset("user:1000", "name", "Alice");
        redis.hset("user:1000", "email", "alice@example.com");
        redis.hset("user:1000", "age", "25");

        auto email = redis.hget("user:1000", "email");
        if (email) {
            std::cout << "HGET user:1000 email: " << *email << std::endl;
        }

        auto user_info = redis.hgetall("user:1000");
        std::cout << "HGETALL user:1000:" << std::endl;
        for (const auto& pair : user_info) {
            std::cout << "  " << pair.first << ": " << pair.second << std::endl;
        }

        // Set operations
        std::cout << "\n=== Set Operations ===" << std::endl;
        redis.sadd("languages", "C++");
        redis.sadd("languages", "Python");
        redis.sadd("languages", "Java");
        redis.sadd("languages", "Go");

        if (redis.sismember("languages", "C++")) {
            std::cout << "SISMEMBER: C++ is in languages" << std::endl;
        }

        auto languages = redis.scard("languages");
        std::cout << "SCARD languages: " << languages << std::endl;

        auto members = redis.smembers("languages");
        std::cout << "SMEMBERS languages:" << std::endl;
        for (const auto& lang : members) {
            std::cout << "  " << lang << std::endl;
        }

        // Sorted set operations
        std::cout << "\n=== Sorted Set Operations ===" << std::endl;
        redis.zadd("scores", 95.5, "Alice");
        redis.zadd("scores", 87.2, "Bob");
        redis.zadd("scores", 92.0, "Charlie");

        auto alice_score = redis.zscore("scores", "Alice");
        if (alice_score) {
            std::cout << "ZSCORE scores Alice: " << *alice_score << std::endl;
        }

        auto count = redis.zcard("scores");
        std::cout << "ZCARD scores: " << count << std::endl;

        // Key operations
        std::cout << "\n=== Key Operations ===" << std::endl;
        redis.expire("name", 60);  // Expire in 60 seconds
        auto ttl = redis.ttl("name");
        std::cout << "TTL name: " << ttl << " seconds" << std::endl;

        if (redis.exists("name")) {
            std::cout << "EXISTS name: key exists" << std::endl;
        }

        std::cout << "\nExample completed successfully!" << std::endl;

    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }

    return 0;
}